package com.shuai.frame.model;


import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ServiceMetaInfo {
    /**
     * 服务名称
     */
    private String serviceName;
    /**
     * 服务主机
     */
    private String serviceHost;
    /**
     * 服务端口
     */
    private int servicePort;
    /**
     * 服务版本号
     */
    private String serviceVersion = "1.0";
    /**
     * 服务分组
     */
    private String serviceGroup = "default";
    /**
     * 服务描述
     */
    private String serviceDesc;

    /**
     * 获取服务key
     */
    public String getServiceKey() {
        return serviceName + ":" + serviceVersion;
    }

    /**
     * 获取服务节点key
     */
    public String getServiceNodeKey() {
        return getServiceKey() + "/" + this.serviceHost + ":" + this.servicePort;
    }

    /**
     * 获取服务地址
     */
    public String getServiceAddress() {
        if (!StrUtil.contains(serviceHost, "http")) {
            return "http://" + serviceHost + ":" + servicePort;
        }
        return serviceHost + ":" + servicePort;
    }
}
